@extends('layouts.empty')

@section('css')
    <style>
            @media print {
                .btn-primary {
                    display:none;
                }
            }
          /****** common ******/
            .background {
            background: #f3f4f3;
            }
            .print-border {
            border: 1px solid #e6e7e6;
            }
            .print-grey-label::before {
            background: #f3f4f3 !important;
            }
            .print-flex {
            display: flex;
            align-items: center;
            padding: 5px 0;
            }
            .margin-10 {
            margin-right: 10px;
            }
            /****** header ******/
            .print-header .print-title {
            font-size: 20px;
            font-weight: 700;
            flex: 1;
            text-align: center;
            border: 1px solid #e6e7e6;
            background: #f3f4f3 !important;
            margin-right: 10px;
            }
            .print-header .print-pay-time {
            margin-right: 10px;
            border: 1px solid #e6e7e6;
            }
            .print-header .print-pay-time::before {
            content: "付款时间：";
            }
            .print-header .print-order-num {
            border: 1px solid #e6e7e6;
            }
            .print-header .print-order-num::before {
            content: "编号：";
            }
            /****** info ******/
            .print-info .print-customer {
            margin-right: 10px;
            border: 1px solid #e6e7e6;
            }
            .print-info .print-customer::before {
            content: "收货人：";
            }
            .print-info .print-tel-number {
            margin-right: 10px;
            border: 1px solid #e6e7e6;
            }
            .print-info .print-tel-number::before {
            content: "电话：";
            }
            .print-info .print-address {
            flex: 1;
            border: 1px solid #e6e7e6;
            }
            .print-info .print-address::before {
            content: "地址：";
            }
            .print-info .print-delivery-time {
            flex: 1;
            margin-right: 10px;
            font-size: 21px;
            font-weight: bold;
            border: 1px solid #e6e7e6;
            }
            .print-info .print-delivery-time::before {
            content: "配送时间：";
            font-weight: normal;
            font-size: 14px;
            }
            .print-info .print-goods-number {
            margin-right: 10px;
            border: 1px solid #e6e7e6;
            }
            .print-info .print-goods-number::before {
            content: "商品总数：";
            }
            .print-info .print-paid-number {
            border: 1px solid #e6e7e6;
            }
            .print-info .print-paid-number::before {
            content: "实付金额：";
            }
            .print-info .print-mark {
            flex: 1;
            font-size: 21px;
            font-weight: bold;
            border: 1px solid #e6e7e6;
            }
            .print-info .print-mark::before {
            content: "买家留言：";
            font-weight: normal;
            font-size: 14px;
            }
            .print-info .print-picker {
            flex: 1;
            margin-right: 10px;
            border: 1px solid #e6e7e6;
            }
            .print-info .print-picker::before {
            content: "客服电话：";
            }
            .print-info .print-postman {
            flex: 1;
            margin-right: 10px;
            border: 1px solid #e6e7e6;
            }
            .print-info .print-postman::before {
            content: "公司地址：";
            }
            .print-info .print-stter {
            flex: 1;
            border: 1px solid #e6e7e6;
            }
            .print-info .print-stter::before {
            content: "制单人：";
            }
            /****** main ******/
            .print-main {
            width: 100%;
            text-align: left;
            border-collapse: collapse;
            }
            .print-main th,
            .print-main td {
            border: 1px solid #000;
            }
    </style>
@endsection

@section('content')
    <div id="print-{!! $order->id !!}" class="print">
    <div class="print-header print-flex">
      <div class="print-title">你好菜 果蔬生鲜配送</div>
      <div class="print-pay-time print-grey-label">{{ $order->pay_at }}</div>
      <div class="print-order-num print-grey-label">{{ $order->sn }}</div>
    </div>
    @if($order->address)
    <div class="print-info print-flex">
      <div class="print-customer print-grey-label">{{$order->address->name}}</div>
      <div class="print-tel-number print-grey-label">{{$order->address->phone}}</div>
      <div class="print-address print-grey-label">{{$order->address->address}}</div>
    </div>
    @endif
    <table class="print-main">
      <thead>
        <tr>
          <th>序号</th>
          <th>商品名称</th>
          <th>规格</th>
          <th>数量</th>
          <th>单价</th>
          <th>小计</th>
          <th>状态</th>
          <th>操作</th>
        </tr>
      </thead>
      <tbody>
        @foreach($order->goods as $k=>$v)
        @if($v->status==12)
        <tr>
          <td>{{ $k+1 }}</td>
          <td><s>{{ $v->goods->name }} {{ $v->goods->title }}</s></td>
          <td><s>{!! $v->attribute_id?$v->attribute->name:'' !!}</s></td>
          <td><s>{{ $v->number }}</s></td>
          <td><s>{{ $v->price }}</s></td>
          <td><s>{{ $v->number*$v->price }}</s></td>
          <td>退款成功</td>
          <td>已退货</td>
        </tr>
        @else
        <tr>
          <td>{{ $k+1 }}</td>
          <td>{{ $v->goods->name }} {{ $v->goods->title }}</td>
          <td>{!! $v->attribute_id?$v->attribute->name:'' !!}</td>
          <td><b>{{ $v->number }}</b></td>
          <td>{{ $v->price }}</td>
          <td>{{ $v->number*$v->price }}</td>
          <td>
              @if($v->status==11)
                  退款中
              @elseif($v->status==12)
                  退款成功
              @elseif($v->status==13)
                  退款失败
              @else
                  正常
              @endif
          </td>
          <td>
              <form action="{!! route('orders.returnGoods') !!}">
                  选择退货数量<input type="hidden" name="orderGoods_id" value="{{ $v->id }}">
                  <input type="hidden" name="order_id" value="{{ $order->id }}">
              <input type="number" name="number" value="{{ $v->number }}"><button type="submit" onclick="return confirm('确定要退货么')">申请单品退货</button>
              </form>
          </td>
        </tr>
        @endif
        @endforeach
        <tr>
          <td colspan="3">合计</td>
          <td><b>{{ $order->goods_number }}</b></td>
          <td></td>
          <td>{{ $order->price }}</td>
          <td>
              @if($order->status==11)
                  订单退款中
              @elseif($order->status==12)
                  订单退款成功
              @elseif($order->status==13)
                  订单退款失败
              @else
                  正常
              @endif
          </td>
          <td style="text-align: center">
            <form action="{!! route('orders.returnOrder') !!}">
                <input type="hidden" name="order_id" value="{{ $order->id }}">
                <button type="submit" style="width: 100px;height: 20px;"  onclick="return confirm('确定要退货么')">整单退货</button>
            </form>
          </td>
        </tr>
      </tbody>
    </table>
    <div class="print-info print-flex">
      <div class="print-delivery-time print-grey-label">
      @if($order->shipping_at)
          {!! substr($order->shipping_at,0,16) !!} - {!! substr($order->shipping_end_at,11,5) !!}
      @else
          {!! $order->will_take==1?'自提':'' !!}
      @endif
      </div>
      <div class="print-goods-number print-grey-label">{{ $order->calculate_goods_number }}</div>
      <div class="print-paid-number print-grey-label">{{ $order->calculate_price }}</div>
    </div>
    <div class="print-info print-flex">
      <div class="print-mark print-grey-label">{{ $order->remark }}</div>
    </div>
    <!-- <div class="print-info print-flex">
      <div class="print-picker print-grey-label">0575-85678813</div>
      <div class="print-postman print-grey-label">柯桥区柯北大道788号金徕旺电子商务园1A区</div>
    </div> -->
        <p>{{ $order->created_at }} <span style="margin-left: 50px">买家下单</span></p>
        @if($order->pay_status=1)
            <p>{{ $order->pay_at }} <span style="margin-left: 50px">买家付款</span></p>
        @endif
        @if($order->pairing_id)
            <p>{{ $order->pairing_tob_at }} <span style="margin-left: 50px">
                    @if(isset($order->pairing))
                        {{ $order->pairing->name }}{{ $order->pairing->phone }}
                    @else
                        无配单员&nbsp;
                    @endif
                        抢到配单</span></p>
        @endif
        @if($order->pairing_at)
            <p>{{ $order->pairing_at }} <span style="margin-left: 50px">
                    @if(isset($order->pairing))
                        {{ $order->pairing->name }}{{ $order->pairing->phone }}
                    @else
                        无配单员&nbsp;
                    @endif
                        完成配单</span></p>
        @endif
        @if($order->verifier_id)
            <p>{{ $order->verify_tob_at }} <span style="margin-left: 50px">
                    @if(isset($order->verifier))
                        {{ $order->verifier->name }}{{ $order->verifier->phone }}
                    @else
                        无验单员&nbsp;
                    @endif
                        抢到验单</span></p>
        @endif
        @if($order->verify_at)
            <p>{{ $order->verify_at }} <span style="margin-left: 50px">
                    @if(isset($order->verifier))
                        {{ $order->verifier->name }}{{ $order->verifier->phone }}
                    @else
                        无验单员&nbsp;
                    @endif
                        完成验单</span></p>
        @endif
        @if($order->courier_id)
            <p>{{ $order->shipping_rob_at }} <span style="margin-left: 50px">
                    @if(isset($order->courier))
                    {{ $order->courier->name }}{{ $order->courier->phone }}
                    @else
                        无配送员&nbsp;
                    @endif
                        抢到送单</span>
            </p>
        @endif
        @if($order->real_shipping_at)
            <p>{{ $order->real_shipping_at }} <span style="margin-left: 50px">
                    @if(isset($order->courier))
                        {{ $order->courier->name }}{{ $order->courier->phone }}
                    @else
                        无配送员&nbsp;
                    @endif
                         开始送单</span></p>
        @endif
        @if($order->real_shipping_end_at)
            <p>{{ $order->real_shipping_end_at }} <span style="margin-left: 50px">
                    @if(isset($order->courier))
                        {{ $order->courier->name }}{{ $order->courier->phone }}
                    @else
                        无配送员&nbsp;
                    @endif
                         完成送单</span></p>
        @endif
  </div>

  {{--<button class="btn btn-primary print-action" style="margin: 30px auto;">打印</button>--}}
@endsection


@section('scripts')
    <script>
        $('.print-action').click(function () {
            window.print();
            $.post('{{ route('api.orders.setPrintState') }}', {ids: {!! $order->id !!}}, function(data) {
               console.log(data);
            });
        })
    </script>
@endsection